public class erFenFIND {

    public static int binarySearch(int[] array,int key){
        int left = 0;
        int right = array.length-1;
        while(left<=right){
            int mid = (left+right)/2;      //CCC写法类似
            if(array[mid]==key){
                return mid;
            }else if(array[mid]==key){
                right=mid-1;
            }else{
                left = mid+1;
            }
        }return -1;
    }

    public static void main(String[] args) {
        int[] array = {4,7,11,12,14,21};
        int index = binarySearch(array,21);
        System.out.println(index);
    }
}
